<template>
    <div class="list-container">
		
		<div class="detail">
		<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
		  <el-form-item label="登录地址" prop="ipaddr">
		    <el-input
		      v-model="queryParams.ipaddr"
		      placeholder="请输入登录地址"
		      clearable
		      size="small"
		      @keyup.enter.native="handleQuery"
		    />
		  </el-form-item>
		  <el-form-item label="用户名称" prop="userName">
		    <el-input
		      v-model="queryParams.userName"
		      placeholder="请输入用户名称"
		      clearable
		      size="small"
		      @keyup.enter.native="handleQuery"
		    />
		  </el-form-item>
		  <el-form-item>
		    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
		    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
		  </el-form-item>
		
		</el-form>
		
		<div class="table">
		  <el-table 
		  border
		  fit
		  header-cell-class-name="table-header-cell"
		  :class="(list.slice((pageNum-1)*pageSize,pageNum*pageSize)).length === 0 ? 'table-empty' : ''"
		  v-loading="loading"
		  :data="list.slice((pageNum-1)*pageSize,pageNum*pageSize)"
		  style="width: 100%;"
		>
		  <el-table-column label="序号" type="index" align="center" width="150">
		    <template slot-scope="scope">
		      <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
		    </template>
		  </el-table-column>
		  <el-table-column label="会话编号" align="center" prop="tokenId" :show-overflow-tooltip="true" width="240"/>
		  <el-table-column label="登录名称" align="center" prop="userName" :show-overflow-tooltip="true" width="200"/>
		  <el-table-column label="部门名称" align="center" prop="deptName" width="200" />
		  <el-table-column label="主机" align="center" prop="ipaddr" :show-overflow-tooltip="true" />
		  <el-table-column label="登录地点" align="center" prop="loginLocation" :show-overflow-tooltip="true" width="200" />
		  <el-table-column label="浏览器" align="center" prop="browser" width="200"/>
		  <el-table-column label="操作系统" align="center" prop="os" width="200" />
		  <el-table-column label="登录时间" align="center" prop="loginTime" width="200">
		    <template slot-scope="scope">
		      <span>{{ parseTime(scope.row.loginTime) }}</span>
		    </template>
		  </el-table-column>
		  <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
		    <template slot-scope="scope">
		      <el-button
		        size="mini"
		        type="text"
		        icon="el-icon-delete"
		        @click="handleForceLogout(scope.row)"
		        v-hasPermi="['monitor:online:forceLogout']"
		      >强退</el-button>
		    </template>
		  </el-table-column> -->
		  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
		    <template slot-scope="scope">
		      <el-button
		        size="mini"
		        type="text"
		        icon="el-icon-delete"
		        @click="handleForceLogout(scope.row)"
		      >强退</el-button>
		    </template>
		  </el-table-column>
		</el-table>
			</div>
			</div>
		<pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />

		

    </div>
</template>
<script>
import { list, forceLogout } from "@/api/monitor/online";
import NavCard from '@/components/nav-card/index.vue'
import BreadCrumb from '@/components/bread-crumb/index.vue'
export default {
  name: "Online",
  components: {
      NavCard,
      BreadCrumb
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        userName: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$modal.confirm('是否确认强退名称为"' + row.userName + '"的数据项？').then(function() {
        return forceLogout(row.tokenId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("强退成功");
      }).catch(() => {});
    }
  }
};
</script>
<style lang="scss" scoped>
.list-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: #F7F8FD;
}

.bread-crumb {
    margin-top: 21px;
    padding-left: 20px;
}

.title {
    font-size: 26px;
    color: #4B4B4B;
    font-weight: bold;
    margin: 0;
    margin-top: 18px;
    padding-left: 20px;
}

.detail {
    margin-top: 23px;
    margin-left: 20px;
    padding: 12px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 5px;

    .search-input {
        width: 264px;
        height: 47px;
        background: #FFFFFF;
        border-radius: 5px;

        ::v-deep input {
            line-height: 45px;
            height: 47px;
            display: inline-block;
        }

        ::v-deep .el-input__icon {
            line-height: 45px;
            height: 45px;
            vertical-align: -0.15em;
            color: #4373F1;
        }
    }

    .table {
        flex: 1;
        background-color: #fff;
        margin: 13px 0 16px;

        ::v-deep .table-header-cell {
            background-color: #EBEFF8;
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        .el-table {
            height: 100%;
        }
        ::v-deep .el-table__cell {
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        :v-deep .el-table__body-wrapper {
            height: 100%;
        }
        :v-deep .el-table__empty-block {
            height: 100%;
        }
        .operation {
            display: flex;
            align-items: center;
            height: 100%;

            .view, .edit, .delete {
                cursor: pointer;
                font-weight: 500;
                font-size: 16px;
                color: #4373F1;
                height: 16px;
                line-height: 16px;
                background-repeat: no-repeat;
                background-position: 0 center;
                user-select: none;
            }
        }
    }
}

.edit-box {
    display: flex;
    flex-direction: column;
    align-items: center;

    ::v-deep .el-dialog__footer {
        display: none;
    }
    
    .row1 {
        display: flex;

        .el-select {
            margin-right: 7px;

            &:nth-last-child(1) {
                margin-right: 0;
            }
        }
    }

    .row2 {
        width: 100%;
        margin-top: 7px;

        .el-select {
            width: 100%;
        }
    }

    .submit {
        width: 164px;
        height: 56px;
        background: #4373F1;
        border-radius: 5px;
        user-select: none;
        line-height: 56px;
        color: #fff;
        text-align: center;
        margin-top: 22px;
        cursor: pointer;
    }
}
.edit-region {
    font-weight: 500;
    font-size: 16px;
    color: #4373F1;
    cursor: pointer;
}
::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
}

.pagination-container{
    background: #f7f8fd;
    padding: 32px 16px;
}
</style>
